#if !defined(_ATOM03_Parser_H_)
#define  _ATOM03_Parser_H_

#include <iostream>
#include "rss_parser.h"
#include "Item.h"

using namespace std;

class ATOM03Parser:public RSSParser
{

public:
	ATOM03Parser()
	{
		/*
		* Simulate XSLT to translate each standard to intermediate DOM structure
		*/
		tag_map_["atom:title"]="title";
		tag_map_["@href"]="url";
		tag_map_["atom:tagline"]="description";
		tag_map_["xml:lang"]="language";
		tag_map_["atom:copyright"]="copyright";
		tag_map_["atom:category"]="category";
		tag_map_["atom:author"]="authorEmail";
		tag_map_["atom:id"]="guid";
		//	tag_map_["image"]="imageUrl";
		tag_map_["atom:issued"]="publishDateTime";
		tag_map_["atom:modified"]="lastUpdatedDateTime";
		tag_map_["atom:content"]="content";
	}

	virtual Item * ParseData(const TiXmlElement* node)
	{
		Item *itm=NULL;
		string real_tag;
		if((node->Type() == TiXmlNode::ELEMENT))
		{
			itm=new Item;

			for( const TiXmlElement* elem= node->FirstChildElement();elem;elem=elem->NextSiblingElement())
			{
				if(elem->GetText())
				{
					//cout<<elem->Value()<<"\t"<<elem->GetText()<<endl;

					/*look up the table, if not exist, we will use the original value*/
					real_tag=tag_map_[elem->Value()];
					if(real_tag.empty()||real_tag.size()==0)
						real_tag=elem->Value();

					itm->AddElem(real_tag,elem->GetText());	

				}
			}
			if(itm->getID().empty()||itm->getID().size()==0)
			{
				itm->ResetID();
			}
		}	
		return itm;
	}
};



#endif
